package com.lachesis.molecule.common.database;

import javax.annotation.PostConstruct;

import org.flywaydb.core.Flyway;
import org.flywaydb.core.internal.util.logging.Log;
import org.flywaydb.core.internal.util.logging.LogFactory;

/** 
 * @ClassName: DbVersionMigrationMonitor 
 * @Description: 数据库版本监测器，根据系统版本与数据版本，同步数据库Schema更新，通过SpringBean注入 
 * @author shiwei.hu shiwei.hu@lacehsis-mh.com
 * @date 2017年10月31日 下午6:27:16 
 *  
 */
public class DbVersionMigrationMonitor {
    
    /** 
     * @Fields log : 日志记录器 
     */ 
    private static final Log log = LogFactory.getLog(DbVersionMigrationMonitor.class);  
    
    private Flyway flyway;
    public void setFlyway(Flyway flyway) {  
        this.flyway = flyway;  
    }  
    
    
    /** 
     * @Title: run
     * @Description: Bean注入后，启动数据版本监测 
     * @throws 
     */
    @PostConstruct  
    public void run() {  
        log.info("[Start] DbMigration run .. ");
        flyway.setBaselineOnMigrate(true);
        flyway.migrate();   
        log.info("[End] DbMigration run .. ");  
    }  
    
    
}